//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.ComponentModel;
using System.Drawing.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using EntLibContrib.Common.Configuration.Design.Editors;
using EntLibContrib.Mapping.Properties;

namespace EntLibContrib.Mapping.Configuration.Design
{
	/// <summary>
	/// Represents a map using an Xml data file.
	/// </summary>
	public sealed class MapNode : MapBaseNode
	{
		#region Fields
		private string columnName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the data transfer object table name.
		/// </summary>
		/// <value>The data transfer object table name for this node.</value>
		[MappingCategory("CategoryProvider")]
		[MappingDescription("MapColumnNameDescription")]
		public string ColumnName
		{
			get { return columnName; }
			set
			{
				if (value != null)
					columnName = value;
			}
		}

		/// <summary>
		/// Gets a <see cref="MapData"/> configuration object using the node data.
		/// </summary>
		/// <value>
		/// A <see cref="MapData"/> configuration object using the node data.
		/// </value>
		[ReadOnly(true)]
		public override MapData MapData
		{
			get { return new MapData(Name, columnName); }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="MapNode"/> class.
		/// </summary>
		public MapNode ()
			: this(new MapData(InternalResources.DefaultMapNodeName, string.Empty))
		{
		}

		/// <summary>
		/// Initialize a new instance of the<see cref="MapNode"/> class with a <see cref="MapData"/> configuration object.
		/// </summary>
		/// <param name="mapData">The map data.</param>
		public MapNode(MapData mapData)
		{
			if (mapData == null)
				throw new ArgumentNullException("mapData");

			Rename(mapData.Name);
			this.columnName = mapData.ColumnName;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Clones this instance.
		/// </summary>
		/// <returns></returns>
		public override MapBaseNode Clone()
		{
			return new MapNode(this.MapData);
		}
		#endregion
	}
}